package utils;

import java.io.Serializable;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.lang.StringUtils;

public class RegularUtil implements Serializable {
	
	private static final long serialVersionUID = 1L;
		
	//整数正则表达式
	public static final String POSITIVE_INTEGER = "^[0-9]*[0-9][0-9]*$";
	
	//电子邮箱正则表达式
	public static final String EMAIL = "^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$";
	
	//座机号码正则表达式 兼容格式: 国家代码(2到3位)-区号(2到3位)-电话号码(7到8位)-分机号(3到5位)
	public static final String TEL = "^(([0\\+]\\d{2,3}-)?(0\\d{2,3})-)(\\d{7,8})(-(\\d{3,5}))?$";
	
	//手机号正则表达式
	public static final String MOBILE = "^1[3-9]\\d{9}$";
	
	// 密码正则表达式
	public static final String PASSWORD = "^[-\\w!@#$%^&*()+=|:;'.></]+$";
	
    //字符串正则表达式
	public static final String STR="^[a-zA-Z]+$";
	
	//数字正则表达式
	public static final String NUM="^[0-9]+$";
	
	//数字加英文字符
	public static final String CHARNUMBER = "^[a-z0-9A-Z_]+$";
	
	//金额正则表达式
	public static final String AMOUNT = "^(([1-9]{1}\\d*)|([0]{1}))(\\.(\\d){0,2})?$";
	
	//物流单号
	public static final String POST="^[A-Z][A-Z][0-9]{9}[A-Z][A-Z]$";
	
	//校验
	public static boolean test(String str,String reg){
		boolean flag = false;
		if(StringUtils.isEmpty(str)){
			return flag;
		}
		str=str.trim();
		Pattern pattern = Pattern.compile(reg); 
		Matcher matcher = pattern.matcher(str); 
		flag = matcher.matches();
		return flag;
	}
	
	
	public static void main(String[] args) {
		System.out.println(test("t3dnewborg_-Dmail",CHARNUMBER));
	}
}
